package com.liuyingxing.javaSpringCloudTest.dao;

import com.liuyingxing.entity.test.Country;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * @File CountryDao.java
 * @Auth liuxing
 * @Date 2021/8/19 15:25
 * @Email liuxing997@foxmail.com
 */
@Mapper
@Repository
public interface CountryDao {

    //根据国家ID查询国家信息
    @Select("select * from test_country where country_id=#{countryId}")
    @Results(id="countryResults", value = {
            @Result(column = "country_id", property = "countryId"),
            @Result(column = "country_id",
                    property = "cities",
                    javaType = List.class,
                    many = @Many(select="com.liuyingxing.javaSpringCloudTest.dao.CityDao.getCitiesByCountryId")
            )
    })
    Country getCountryByCountryId(int countryId);

    //按国家名称获取国家信息
    @Select("select * from test_country where country_name=#{countryName} and local_country_name=#{localCountryName}")
    @ResultMap(value = "countryResults")
    Country getCountryByCountryName(@Param("countryName") String countryName,
                                    @Param("localCountryName") String localCountryName);
}
